home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / Mic-1 v1.0 / Project and Source / Source / mic_data_path.cpp < prev    next >
Text File  |  1996-05-17  |  6KB  |  247 lines

  1. /*
  2.     "mic_data_path.cpp"
  3.     
  4.     This file contains Mic-1 objects which fall in the "data path" catagory, such as
  5.     the ScratchPad, ALU, and shifter. Also defined is the common register.
  6. */
  7.  
  8. #include <iostream.h>
  9. #include <fstream.h>
  10. #include <iomanip.h>
  11.  
  12. #include "mic_main.h"
  13. #include "mic_memory.h"
  14. #include "mic_data_path.h"
  15. #include "mic_control.h"
  16.  
  17. #pragma mark ••• MAR •••
  18.  
  19. void MARClass::output (Mic_1_Class& Mic)
  20. {
  21.     Mic.Memory.input_MAR(Mic, word);
  22. }
  23.  
  24. ostream& operator << (ostream& s, MARClass& m)
  25. {
  26.     s << hex << uppercase;
  27.     s << "MAR:" << endl;
  28.     s << "  ADDR: " << setw(4) << setfill('0') << right << m.word << endl;
  29.     s << "  ENABLED: " << m.mar_enabled << endl;
  30.     s << resetiosflags(ios::hex | ios::uppercase);
  31.     return s;
  32. }
  33.  
  34. #pragma mark ---------------------------------
  35. #pragma mark ••• MBR •••
  36.  
  37. void MBRClass::input_Memory (unsigned short newWord)
  38. {
  39.     if (read_enabled)
  40.         word = newWord;
  41. }
  42.  
  43. void MBRClass::input_Shifter (unsigned short newWord)
  44. {
  45.     if (mbr_enabled)
  46.         word = newWord;
  47. }
  48.  
  49. void MBRClass::output (Mic_1_Class& Mic)
  50. {
  51.     if (write_enabled)
  52.         Mic.Memory.input_MBR(Mic, word);
  53.     //if (read_enabled)
  54.         Mic.AMUX.input_MBR(Mic, word);
  55. }
  56.  
  57. ostream& operator << (ostream& s, MBRClass& m)
  58. {
  59.     s << hex << uppercase;
  60.     s << "MBR:" << endl;
  61.     s << "  MBR WORD: " << setw(4) << setfill('0') << right << m.word << endl;
  62.     s << "  READ: " << m.read_enabled << endl;
  63.     s << "  WRITE: " << m.write_enabled << endl;
  64.     s << "  ENABLED: " << m.mbr_enabled << endl;
  65.     s << resetiosflags(ios::hex | ios::uppercase);
  66.     return s;
  67. }
  68.  
  69. #pragma mark ---------------------------------
  70. #pragma mark ••• SCRATCHPAD •••
  71.  
  72. ScratchPadClass::ScratchPadClass()
  73. {
  74.     registers[0]  = 0;            // PC
  75.     registers[1]  = 0;            // AC
  76.     registers[2]  = 0;            // SP
  77.     registers[3]  = 0;            // IR
  78.     registers[4]  = 0;            // TIR
  79.     registers[5]  = 0;            // 0
  80.     registers[6]  = 1;            // +1
  81.     registers[7]  = -1;            // -1
  82.     registers[8]  = 0x0FFF;    // AMASK
  83.     registers[9]  = 0x00FF;    // SMASK
  84.     registers[10] = 0;            // A
  85.     registers[11] = 0;            // B
  86.     registers[12] = 0;            // C
  87.     registers[13] = 0;            // D
  88.     registers[14] = 0;            // E
  89.     registers[15] = 0;            // F
  90.     
  91.     shifter_word = 0;
  92.     selection_a = 0;
  93.     selection_b = 0;
  94.     selection_c = 0;
  95.     c_enabled = false;
  96. }
  97.  
  98. void ScratchPadClass::output (Mic_1_Class& Mic)
  99. {
  100.     Mic.A_Latch.input_ScratchPad(registers[selection_a]);
  101.     Mic.B_Latch.input_ScratchPad(registers[selection_b]);
  102. }
  103.  
  104. ostream& operator << (ostream& s, ScratchPadClass& scratch)
  105. {
  106.     s << hex << uppercase;
  107.     s << "SCRATCHPAD:" << endl;
  108.     s << "  INPUT WORD: " << setw(4) << setfill('0') << right << scratch.shifter_word << endl;
  109.     s << resetiosflags(ios::hex | ios::uppercase);
  110.     s << "  SELECTION A: " << scratch.selection_a << endl;
  111.     s << "  SELECTION B: " << scratch.selection_b << endl;
  112.     s << "  SELECTION C: " << scratch.selection_c << endl;
  113.     s << "  LOAD ENABLED: " << scratch.c_enabled << endl;
  114.     s << "  REGISTERS:" << endl;
  115.     s << hex << uppercase;
  116.     for (int i=0; i<16; i++)
  117.         s << "    " << i << " " << setw(4) << setfill('0') << right << scratch.registers[i] << endl;
  118.     s << resetiosflags(ios::hex | ios::uppercase);
  119.     return s;
  120. }
  121.  
  122. #pragma mark ---------------------------------
  123. #pragma mark ••• AMUX •••
  124.  
  125. void AMUXClass::output (Mic_1_Class& Mic)
  126. {
  127.     if (from_mbr)
  128.         Mic.ALU.input_AMUX(Mic, mbr_word);
  129.     else
  130.         Mic.ALU.input_AMUX(Mic, a_latch_word);
  131. }
  132.  
  133. ostream& operator << (ostream& s, AMUXClass& a)
  134. {
  135.     s << "AMUX:" << endl;
  136.     s << "  MBR WORD: " << setw(4) << setfill('0') << right << a.mbr_word << endl;
  137.     s << "  A_LATCH WORD: " << setw(4) << setfill('0') << right << a.a_latch_word << endl;
  138.     s << "  SWITCH (0=A_LATCH, 1=MBR): " << a.from_mbr << endl;
  139.     s << resetiosflags(ios::hex | ios::uppercase);
  140.     return s;
  141. }
  142.  
  143. #pragma mark ---------------------------------
  144. #pragma mark ••• ALU •••
  145.  
  146. void ALUClass::output (Mic_1_Class& Mic)
  147. {
  148.     unsigned short word = 0;
  149.     
  150.     switch (operation)
  151.     {
  152.         case (0):        word = amux_word + b_latch_word;        break;    // A + B
  153.         case (1):        word = amux_word & b_latch_word;        break;    // A & B
  154.         case (2):        word = amux_word;                                        break;    // A
  155.         case (3):        word = ~amux_word;                                    break;    // not A
  156.     }
  157.     if ((word >> 15) == 1)
  158.         negative = true;
  159.     else
  160.         negative = false;
  161.     
  162.     if (word == 0)
  163.         zero = true;
  164.     else
  165.         zero = false;
  166.     
  167.     Mic.MicroSeq.input_negative(negative);
  168.     Mic.MicroSeq.input_zero(Mic, zero);
  169.     Mic.Shifter.input_ALU(Mic, word);
  170. }
  171.  
  172. ostream& operator << (ostream& s, ALUClass& a)
  173. {
  174.     s << hex << uppercase;
  175.     s << "ALU:" << endl;
  176.     s << "  AMUX WORD: " << setw(4) << setfill('0') << right << a.amux_word << endl;
  177.     s << "  B_LATCH WORD: " << setw(4) << setfill('0') << right << a.b_latch_word << endl;
  178.     s << "  OPERATION: " << a.operation << endl;
  179.     s << "  NEGATIVE: " << a.negative << endl;
  180.     s << "  ZERO: " << a.zero << endl;
  181.     s << resetiosflags(ios::hex | ios::uppercase);
  182.     return s;
  183. }
  184.  
  185. #pragma mark ---------------------------------
  186. #pragma mark ••• SHIFTER •••
  187.  
  188. void ShifterClass::input_ALU (Mic_1_Class& Mic, unsigned short newWord)
  189. {
  190.     word = newWord;
  191.     switch (option)
  192.     {
  193.         case (0):    break;                            // do nothing
  194.         case (1):    word >>= 1; break;    // shift right 1 bit
  195.         case (2):    word <<= 1; break;    // shift left 1 bit
  196.     }
  197.     output(Mic);
  198. }
  199.  
  200. void ShifterClass::output (Mic_1_Class& Mic)
  201. {
  202.     Mic.MBR.input_Shifter(word);
  203.     Mic.ScratchPad.input_Shifter(word);
  204. }
  205.  
  206. ostream& operator << (ostream& s, ShifterClass& a)
  207. {
  208.     s << hex << uppercase;
  209.     s << "SHIFTER: " << endl;
  210.     s << "  WORD: " << setw(4) << setfill('0') << right << a.word << endl;
  211.     s << "  OPTION: " << a.option << endl;
  212.     s << resetiosflags(ios::hex | ios::uppercase);
  213.     return s;
  214. }
  215.  
  216. #pragma mark ---------------------------------
  217. #pragma mark ••• A_LATCH •••
  218.  
  219. void A_LatchClass::output (Mic_1_Class& Mic)
  220. {
  221.     Mic.AMUX.input_A_Latch(Mic, word);
  222. }
  223.  
  224. ostream& operator << (ostream& s, A_LatchClass& a)
  225. {
  226.     s << hex << uppercase;
  227.     s << "A LATCH: " << setw(4) << setfill('0') << right << a.word << endl;
  228.     s << resetiosflags(ios::hex | ios::uppercase);
  229.     return s;
  230. }
  231.  
  232. #pragma mark ---------------------------------
  233. #pragma mark ••• B_LATCH •••
  234.  
  235. void B_LatchClass::output (Mic_1_Class& Mic)
  236. {
  237.     Mic.MAR.input_B_Latch(word);
  238.     Mic.ALU.input_B_Latch(Mic, word);
  239. }
  240.  
  241. ostream& operator << (ostream& s, B_LatchClass& b)
  242. {
  243.     s << hex << uppercase;
  244.     s << "B LATCH: " << setw(4) << setfill('0') << right << b.word << endl;
  245.     s << resetiosflags(ios::hex | ios::uppercase);
  246.     return s;
  247. }